<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <meta name="author" content="隐星魂 (Roy.Sun)">
        
        <link rel="shortcut icon" href="../../img/favicon.ico">
        <title>13.玄武C库 - 玄武操作系统</title>
        <link href="../../css/bootstrap.min.css" rel="stylesheet">
        <link href="../../css/font-awesome.min.css" rel="stylesheet">
        <link href="../../css/base.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.3/styles/color-brewer.min.css">

        <script src="../../js/jquery-1.10.2.min.js" defer></script>
        <script src="../../js/bootstrap.min.js" defer></script>
        <script src="https://cdn.staticfile.org/highlight.js/10.0.3/highlight.min.js"></script>
        <script>hljs.initHighlightingOnLoad();</script> 
    </head>

    <body>
        <div class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
            <div class="container">
                <a class="navbar-brand" href="../..">玄武操作系统</a>
                <!-- Expander button -->
                <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <!-- Expanded navigation -->
                <div id="navbar-collapse" class="navbar-collapse collapse">
                        <!-- Main navigation -->
                        <ul class="nav navbar-nav">
                            <li class="navitem">
                                <a href="../.." class="nav-link">主页</a>
                            </li>
                            <li class="navitem">
                                <a href="../../License/" class="nav-link">开源协议</a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">快速开发指南 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">STM32</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../QuickGuide/stm32/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/stm32/02-atkh743/" class="dropdown-item">02-正点原子阿波罗H743开发板上手指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/stm32/03-fk429m/" class="dropdown-item">03-反客F429核心板上手指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/stm32/04-atkf103core/" class="dropdown-item">04-正点原子F103核心板上手指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/stm32/05-atkf407core/" class="dropdown-item">05-正点原子F407核心板上手指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/stm32/06-WeActH750/" class="dropdown-item">06-微行电子H750开发板上手指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/stm32/07-Project-From-Scratch-Guide/" class="dropdown-item">07-自定义工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">GD32</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../QuickGuide/gd32/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/gd32/02-Project-Setup-Guide/" class="dropdown-item">02-工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">GD32V</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../QuickGuide/gd32v/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/gd32v/02-Project-Setup-Guide/" class="dropdown-item">02-工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">NXP S32K</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../QuickGuide/s32k/01-Envsetup-Guide/" class="dropdown-item">01-开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../QuickGuide/s32k/02-Project-Setup-Guide/" class="dropdown-item">02-工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">玄武内核模块</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../QuickGuide/xwko/01-XuanWuKO-Guide/" class="dropdown-item">01-上手指南</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown active">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">应用手册 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../00-Index/" class="dropdown-item">0.目录</a>
</li>
                                    
<li>
    <a href="../01-Brief/" class="dropdown-item">1.简介</a>
</li>
                                    
<li>
    <a href="../02-Basic-System-Architecture/" class="dropdown-item">2.系统基本架构</a>
</li>
                                    
<li>
    <a href="../03-Build-System/" class="dropdown-item">3.构建系统</a>
</li>
                                    
<li>
    <a href="../04-Boot-Flow/" class="dropdown-item">4.启动流程</a>
</li>
                                    
<li>
    <a href="../05-IRQ/" class="dropdown-item">5.中断控制</a>
</li>
                                    
<li>
    <a href="../06-SKD/" class="dropdown-item">6.调度器</a>
</li>
                                    
<li>
    <a href="../07-Thread/" class="dropdown-item">7.线程</a>
</li>
                                    
<li>
    <a href="../08-SWT/" class="dropdown-item">8.软件定时器</a>
</li>
                                    
<li>
    <a href="../09-PM/" class="dropdown-item">9.电源管理</a>
</li>
                                    
<li>
    <a href="../10-Lock/" class="dropdown-item">10.锁</a>
</li>
                                    
<li>
    <a href="../11-Sync/" class="dropdown-item">11.同步</a>
</li>
                                    
<li>
    <a href="../12-MM/" class="dropdown-item">12.内存管理</a>
</li>
                                    
<li>
    <a href="./" class="dropdown-item active">13.玄武C库</a>
</li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Lua手册 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../LuaManual/00-Index/" class="dropdown-item">0.目录</a>
</li>
                                    
<li>
    <a href="../../LuaManual/01-Brief/" class="dropdown-item">1.简介</a>
</li>
                                    
<li>
    <a href="../../LuaManual/02-XWXT/" class="dropdown-item">2.全局导出表</a>
</li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">3.XWOS内核</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../LuaManual/03-XWOS/01-SDK/" class="dropdown-item">3.1.线程库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/02-Spinlock/" class="dropdown-item">3.2.自旋锁库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/03-Seqlock/" class="dropdown-item">3.3.顺序锁库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/04-Mutex/" class="dropdown-item">3.4.互斥锁库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/05-Semaphore/" class="dropdown-item">3.5.信号量库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/06-Condition/" class="dropdown-item">3.6.条件量库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/07-Flag/" class="dropdown-item">3.7.事件标志库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/08-Barrier/" class="dropdown-item">3.8.线程栅栏库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/09-Selector/" class="dropdown-item">3.9.信号选择器库</a>
</li>
            
<li>
    <a href="../../LuaManual/03-XWOS/10-PM/" class="dropdown-item">3.10.电源管理</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">4.玄武Lua函数库</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../LuaManual/04-XWLIB/01-Bitmap/" class="dropdown-item">4.1.位图</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">5.设备栈</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../LuaManual/05-XWDS/01-Soc/" class="dropdown-item">5.1.SOC</a>
</li>
            
<li>
    <a href="../../LuaManual/05-XWDS/02-GPIO/" class="dropdown-item">5.2.GPIO</a>
</li>
            
<li>
    <a href="../../LuaManual/05-XWDS/03-UART/" class="dropdown-item">5.3.UART</a>
</li>
            
<li>
    <a href="../../LuaManual/05-XWDS/04-SPI-Master/" class="dropdown-item">5.4.SPI Master</a>
</li>
            
<li>
    <a href="../../LuaManual/05-XWDS/05-IIC-Master/" class="dropdown-item">5.5.IIC Master</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">移植笔记 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../PortingNote/00-Index/" class="dropdown-item">目录</a>
</li>
                                    
<li>
    <a href="../../PortingNote/01-Porting-Note/" class="dropdown-item">移植笔记</a>
</li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">ARM-Cortex-M</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../PortingNote/02-ARM-Cortex-M/01-ARM-Cortex-M-Porting-Note/" class="dropdown-item">架构移植笔记</a>
</li>
            
<li>
    <a href="../../PortingNote/02-ARM-Cortex-M/02-STM32-Porting-Note/" class="dropdown-item">STM32</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">RISC-V</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../PortingNote/03-RISC-V/01-GD32V-Porting-Note/" class="dropdown-item">GD32V</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">规范 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../Specification/00-Index/" class="dropdown-item">目录</a>
</li>
                                    
<li>
    <a href="../../Specification/01-Git-Commit-Specification/" class="dropdown-item">git-commit规范</a>
</li>
                                    
<li>
    <a href="../../Specification/02-Version-Branch-Specification/" class="dropdown-item">版本分支规范</a>
</li>
                                </ul>
                            </li>
                        </ul>

                    <ul class="nav navbar-nav ml-auto">
                        <li class="nav-item">
                            <a href="#" class="nav-link" data-toggle="modal" data-target="#mkdocs_search_modal">
                                <i class="fa fa-search"></i> 搜索
                            </a>
                        </li>
                            <li class="nav-item">
                                <a rel="prev" href="../12-MM/" class="nav-link">
                                    <i class="fa fa-arrow-left"></i> 上一篇
                                </a>
                            </li>
                            <li class="nav-item">
                                <a rel="next" href="../../LuaManual/00-Index/" class="nav-link">
                                    下一篇 <i class="fa fa-arrow-right"></i>
                                </a>
                            </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
            <div class="row">
                    <div class="col-md-3"><div class="navbar-light navbar-expand-md bs-sidebar hidden-print affix" role="complementary">
    <div class="navbar-header">
        <button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#toc-collapse" title="Table of Contents">
            <span class="fa fa-angle-down"></span>
        </button>
    </div>

    
    <div id="toc-collapse" class="navbar-collapse collapse card bg-secondary">
        <ul class="nav flex-column">
            
            <li class="nav-item" data-level="1"><a href="#c" class="nav-link">玄武C库</a>
              <ul class="nav flex-column">
            <li class="nav-item" data-level="2"><a href="#_1" class="nav-link">位操作</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#_5" class="nav-link">位图操作</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#_9" class="nav-link">原子操作</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#_14" class="nav-link">位图原子操作</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#crc" class="nav-link">CRC</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#_18" class="nav-link">日志</a>
              <ul class="nav flex-column">
              </ul>
            </li>
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#_21" class="nav-link">附录</a>
              <ul class="nav flex-column">
              </ul>
            </li>
        </ul>
    </div>
</div></div>
                    <div class="col-md-9" role="main">

<h1 id="c">玄武C库</h1>
<h2 id="_1">位操作</h2>
<h3 id="_2">描述</h3>
<p>玄武C库中提供了位操作模板库，<a href="../02-Basic-System-Architecture/#基本类型">基本类型</a>定义的
各种类型都可使用位操作。位操作模板的第一个参数都为基本类型。</p>
<h3 id="_3">示例</h3>
<pre><code class="C">xwssq_t idx;
/* 从最低位开始查找数据&quot;0&quot;中第一个被置1的位，结果为-1 */
idx = xwbop_ffs(xwu32_t, 0);

/* 从最低位开始查找数据&quot;0xF0&quot;中第一个被置1的位，结果为4 */
idx = xwbop_ffs(xwu32_t, 0xF0);

 /* 将数据0xAA进行镜像翻转，结果为0x55 */
xwu32_t rdata = xwbop_rbit(xwu32_t, 0xAA);
</code></pre>

<h3 id="_4">配置</h3>
<h5 id="cfgxwosh">cfg/xwos.h</h5>
<ul>
<li>玄武C库：<ul>
<li>位操作：<ul>
<li>XWLIBCFG_XWBOP_FFS8：是否启用函数xwbop_ffs8()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FLS8：是否启用函数xwbop_fls8()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RBIT8：是否启用函数xwbop_rbit8()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FFS16：是否启用函数xwbop_ffs16()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FLS16：是否启用函数xwbop_fls16()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RBIT16：是否启用函数xwbop_rbit16()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RE16：是否启用函数xwbop_re16()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RE16S32：是否启用函数xwbop_re16s32()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FFS32：是否启用函数xwbop_ffs32()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FLS32：是否启用函数xwbop_fls32()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RBIT32：是否启用函数xwbop_rbit32()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RE32：是否启用函数xwbop_re32()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RE32S64：是否启用函数xwbop_re32s64()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FFS64：是否启用函数xwbop_ffs64()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_FLS64：是否启用函数xwbop_fls64()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RBIT64：是否启用函数xwbop_rbit64()，取值：1|0；</li>
<li>XWLIBCFG_XWBOP_RE64：是否启用函数xwbop_re64()，取值：1|0；</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="api">API参考</h3>
<ul>
<li>头文件：<strong>xwos/lib/xwbop.h</strong></li>
<li>注释：见头文件</li>
</ul>
<h2 id="_5">位图操作</h2>
<h3 id="_6">描述</h3>
<p>玄武OS中使用<strong>xwbmp_t</strong>来表示位图，<strong>xwbmp_t</strong>是一个32bit的数据类型，
当位图数量多余32bit时，使用<strong>xwbmp_t</strong>数组来表示位图。</p>
<h3 id="_7">示例</h3>
<pre><code class="C">xwssq_t idx;
xwbmpop_declare(mybitmap, 100); /**&lt; 声明一个100位的位图 */

xwbmpop_c0all(mybitmap, 100); /**&lt; 将位图全部清0 */
xwbmpop_x1i(mybitmap, 8); /**&lt; 将位8翻转 */
idx = xwbmp0p_ffs(mybitmap, 100); /**&lt; 从最低位起查找第一个为1的位的序号，结果：8 */
</code></pre>

<h3 id="_8">配置</h3>
<p>(无)</p>
<h3 id="api_1">API参考</h3>
<ul>
<li>头文件：<strong>xwos/lib/xwbop.h</strong></li>
<li>注释：见头文件</li>
</ul>
<h2 id="_9">原子操作</h2>
<h3 id="_10">描述</h3>
<p>玄武C库中提供了原子操作库，<a href="../02-Basic-System-Architecture/#基本类型">基本类型</a>定义的各种类型都
可使用原子操作。</p>
<h3 id="_11">用法</h3>
<p>C11标准中增加了原子操作库，玄武OS的基本类型可以使用标准原子操作库中的函数，
也可以使用玄武OS自己的原子操作库。</p>
<p>玄武OS原子操作库提供了大量函数模板。这些原子操作分为以下几类：</p>
<ul>
<li>读<ul>
<li><strong>xwaop_load()</strong><ul>
<li>可以指定C11中6种内存序</li>
</ul>
</li>
<li><strong>xwaop_read()</strong><ul>
<li>内存序：acquire</li>
</ul>
</li>
</ul>
</li>
<li>写<ul>
<li><strong>xwaop_store()</strong><ul>
<li>可以指定C11中6种内存序</li>
</ul>
</li>
<li><strong>xwaop_write()</strong><ul>
<li>内存序：release</li>
</ul>
</li>
</ul>
</li>
<li>读-改-写<ul>
<li>基本运算：*xwaop_add()*, <strong>xwaop_sub()</strong>, <strong>xwaop_rsb()</strong><ul>
<li>内存序：acq_rel</li>
</ul>
</li>
<li>位运算： <strong>xwaop_and()</strong>, <strong>xwaop_or()</strong>, <strong>xwaop_xor()</strong><ul>
<li>内存序：acq_rel</li>
</ul>
</li>
<li>位操作： <strong>xwaop_s1m()</strong>, <strong>xwaop_c0m()</strong>, <strong>xwaop_x1m()</strong><ul>
<li>内存序：acq_rel</li>
</ul>
</li>
</ul>
</li>
<li>读-测试-改-写<ul>
<li>所有匹配正则表达式<strong>xwaop_t.+_then_.+</strong>的函数<ul>
<li>分为两种情况<ul>
<li>测试成功，继续执行“改-写”操作，此时内存序为acq_rel</li>
<li>测试失败，相当于读操作，此时内存序为consume</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="_12">示例</h3>
<pre><code class="C">xwer_t rc;
__xwcc_atomic xwsq_t refcnt = v;
xwsq_t nv, ov;

/*
 * 测试refcnt是否为0：
 * + ture: refcnt增加1，nv返回refcnt增加以后的新值，ov返回refcnt增加以前的旧值，
 *         内存序：acq_rel，rc为返回值XWOK；
 * + false: nv与ov都返回refcnt的值，内存序：consume，rc为返回值-EACCES；
 */
rc = xwaop_teq_then_add(xwsq_t, &amp;refcnt, 0, 1, &amp;nv, &amp;ov);
</code></pre>

<h3 id="_13">配置</h3>
<h5 id="cfgxwosh_1">cfg/xwos.h</h5>
<ul>
<li>玄武C库：<ul>
<li>原子操作：<ul>
<li>XWLIBCFG_XWAOP8：是否启用8位原子操作库，取值：1|0；</li>
<li>XWLIBCFG_XWAOP16：是否启用16位原子操作库，取值：1|0；</li>
<li>XWLIBCFG_XWAOP32：是否启用32位原子操作库，取值：1|0；</li>
<li>XWLIBCFG_XWAOP64：是否启用64位原子操作库，取值：1|0；</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="api_2">API参考</h3>
<ul>
<li>头文件：<strong>xwos/lib/xwaop.h</strong></li>
<li>注释：见头文件</li>
</ul>
<h2 id="_14">位图原子操作</h2>
<h3 id="_15">描述</h3>
<p>玄武C库中提供了对位图<strong>xwbmp_t</strong>数组的原子操作库。
位图原子操作分为以下几类：</p>
<ul>
<li>读<ul>
<li><strong>xwbmpaop_t1i()</strong><ul>
<li>内存序：consume</li>
</ul>
</li>
</ul>
</li>
<li>写<ul>
<li><strong>xwbmpaop_s1all()</strong>, <strong>xwbmpaop_c0all()</strong><ul>
<li>内存序：acq_rel</li>
</ul>
</li>
</ul>
</li>
<li>读-改-写<ul>
<li><strong>xwbmpaop_s1i()</strong>, <strong>xwbmpaop_c1i()</strong>, <strong>xwbmpaop_x1i()</strong><ul>
<li>内存序：acq_rel</li>
</ul>
</li>
</ul>
</li>
<li>读-测试-改-写<ul>
<li>所有名字匹配正则表达式<strong>xwbmpaop_.+_then_.+</strong>的函数<ul>
<li>分为两种情况<ul>
<li>测试成功，继续执行“改-写”操作，此时内存序为acq_rel</li>
<li>测试失败，相当于读操作，此时内存序为consume</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="_16">配置</h3>
<h5 id="cfgxwosh_2">cfg/xwos.h</h5>
<ul>
<li>玄武C库：<ul>
<li>原子操作：<ul>
<li>XWLIBCFG_XWBMPAOP：是否启用位图原子操作库，取值：1|0；</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="api_3">API参考</h3>
<ul>
<li>头文件：<strong>xwos/lib/xwbmpaop.h</strong></li>
<li>注释：见头文件</li>
</ul>
<h2 id="crc">CRC</h2>
<h3 id="_17">配置</h3>
<h5 id="cfgxwosh_3">cfg/xwos.h</h5>
<ul>
<li>玄武C库：<ul>
<li>CRC：<ul>
<li>XWLIBCFG_CRC32：是否启用CRC32，取值：1|0；</li>
<li>XWLIBCFG_CRC32_0X04C11DB7：是否启用CRC32多项式0x04C11DB7，取值：1|0；</li>
<li>XWLIBCFG_CRC32_0XEDB88320：是否启用CRC32多项式0xEDB88320，取值：1|0；</li>
<li>XWLIBCFG_CRC8：是否启用CRC8，取值：1|0；</li>
<li>XWLIBCFG_CRC8_0X07：是否启用CRC8多项式0x07，取值：1|0；</li>
<li>XWLIBCFG_CRC8_0X31：是否启用CRC8多项式0x31，取值：1|0；</li>
<li>XWLIBCFG_CRC8_0X9B：是否启用CRC8多项式0x9B，取值：1|0；</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="api_4">API参考</h3>
<ul>
<li>头文件：<strong>xwos/lib/crc32.h</strong></li>
<li>注释：见头文件</li>
</ul>
<h2 id="_18">日志</h2>
<h3 id="_19">描述</h3>
<p>玄武OS提供了日志框架，用户可以输出带有等级的日志：</p>
<ul>
<li>VERBOSE，等级1，冗长</li>
<li>DEBUG，等级2，调试</li>
<li>INFO，等级3，信息</li>
<li>NOTICE，等级4，提醒</li>
<li>WARNING，等级5，警告</li>
<li>ERR，等级6，错误</li>
<li>CRIT，等级7，危险</li>
<li>EMERG，等级8，紧急</li>
</ul>
<p>用户可以通过配置<strong>XWLIBCFG_XWLOG_LEVEL</strong>来控制各种等级的日志是否输出：</p>
<ul>
<li>当等级大于等于<strong>XWLIBCFG_XWLOG_LEVEL</strong>的日志才会输出，</li>
<li>当<strong>XWLIBCFG_XWLOG_LEVEL</strong>配置为0将关闭所有日志。</li>
</ul>
<p>玄武OS的日志框架需要用户在BSP中提供后端驱动接口，以决定日志最终输出到串口、
SD卡、还是别的设备：</p>
<ul>
<li>当配置<strong>SOCCFG_LOG</strong>为1时，BSP中需要提供函数<strong>soc_log_write()</strong>；</li>
<li>当配置<strong>BRDCFG_LOG</strong>为1时，BSP中需要提供函数<strong>board_log_write()</strong>；</li>
<li>当配置<strong>SOCCFG_LOG</strong>与配置<strong>BRDCFG_LOG</strong>同时为1时，<strong>SOCCFG_LOG</strong>具有更高
    优先级；</li>
</ul>
<h3 id="_20">配置</h3>
<h5 id="cfgxwosh_4">cfg/xwos.h</h5>
<ul>
<li>玄武C库：<ul>
<li>日志<ul>
<li>XWLIBCFG_LOG：是否启用Log调试，取值：1|0；</li>
<li>XWLIBCFG_XWLOG_LEVEL：最低日志等级；</li>
<li>XWLIBCFG_XWLOG_BUFSIZE：日志缓冲区大小；</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="api_5">API参考</h3>
<ul>
<li>头文件：<strong>xwos/lib/xwlog.h</strong></li>
<li>注释：见头文件</li>
</ul>
<h1 id="_21">附录</h1>
<ul>
<li><a href="../00-Index/">返回目录</a></li>
</ul></div>
            </div>
        </div>

        <footer class="col-md-12">
            <hr>
            <p>Documentation built with <a href="https://www.mkdocs.org/">MkDocs</a>.</p>
        </footer>
        <script>
            var base_url = "../..",
                shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
        </script>
        <script src="../../js/base.js" defer></script>
        <script src="../../search/main.js" defer></script>

        <div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="searchModalLabel">搜索</h4>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body">
                <p>
                    在这里所有文档：
                </p>
                <form>
                    <div class="form-group">
                        <input type="search" class="form-control" placeholder="搜索..." id="mkdocs-search-query" title="Type search term here">
                    </div>
                </form>
                <div id="mkdocs-search-results"></div>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="keyboardModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="keyboardModalLabel">Keyboard Shortcuts</h4>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body">
              <table class="table">
                <thead>
                  <tr>
                    <th style="width: 20%;">Keys</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td class="help shortcut"><kbd>?</kbd></td>
                    <td>Open this help</td>
                  </tr>
                  <tr>
                    <td class="next shortcut"><kbd>n</kbd></td>
                    <td>Next page</td>
                  </tr>
                  <tr>
                    <td class="prev shortcut"><kbd>p</kbd></td>
                    <td>Previous page</td>
                  </tr>
                  <tr>
                    <td class="search shortcut"><kbd>s</kbd></td>
                    <td>Search</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

    </body>
</html>
